@extends('admin.public')

@section('content')
    <div class="col-md-12">
        <section class="panel panel-default text-sm doc-buttons">
            <div class="panel-body">
                <a href="{{ route('admin.info.info_add',$chunk->id) }}" class="btn btn-info"><i
                            class="icon-plus ico"></i>
                    &nbsp; 添加信息</a>
                <a href="{{ route('admin.info.trash',$chunk->id) }}" class="btn btn-danger"><i
                            class="icon-trash ico"></i>
                    &nbsp; 回收站</a>
            </div>
        </section>
    </div>

    <div class="col-md-12">
        <section class="panel panel-default">
            <header class="panel-heading">
                {{ $chunk->name }}{{ $frame['title'] }}
            </header>
            <div class="row wrapper">
                <div class="col-sm-5 m-b-xs">
                    <form action="" method="get">
                        <select class="input-sm form-control input-s-sm inline v-middle" name="sort">
                            @if( !empty($sorts) )
                                @foreach( $sorts as $sortlv1 )
                                    <option value="{{ $sortlv1['id'] }}" {{ $append['sort']==$sortlv1['id']?'selected':'' }}>
                                        {{ $sortlv1['name'] }}
                                    </option>
                                    @if( !empty($sortlv1['children']) )
                                        @foreach( $sortlv1['children'] as $sortlv2 )
                                            <option value="{{ $sortlv2['id'] }}" {{ $append['sort']==$sortlv2['id']?'selected':'' }}>
                                                --{{ $sortlv2['name'] }}
                                            </option>
                                            @if( !empty($sortlv2['children']) )
                                                @foreach( $sortlv2['children'] as $sortlv3 )
                                                    <option value="{{ $sortlv3['id'] }}" {{ $append['sort']==$sortlv3['id']?'selected':'' }}>
                                                        ----{{ $sortlv3['name'] }}
                                                    </option>
                                                    @if( !empty($sortlv3['children']) )
                                                        @foreach( $sortlv3['children'] as $sortlv4 )
                                                            <option value="{{ $sortlv4['id'] }}" {{ $append['sort']==$sortlv4['id']?'selected':'' }}>
                                                                ----{{ $sortlv4['name'] }}
                                                            </option>
                                                            @if( !empty($sortlv4['children']) )
                                                                @foreach( $sortlv4['children'] as $sortlv5 )
                                                                    <option value="{{ $sortlv5['id'] }}" {{ $append['sort']==$sortlv5['id']?'selected':'' }}>
                                                                        ----{{ $sortlv5['name'] }}
                                                                    </option>
                                                                @endforeach
                                                            @endif
                                                        @endforeach
                                                    @endif
                                                @endforeach
                                            @endif
                                        @endforeach
                                    @endif
                                @endforeach
                            @endif
                        </select>
                        <button class="btn btn-sm btn-default">查询</button>
                    </form>
                </div>
                <div class="col-sm-4 m-b-xs">
                    <div class="btn-group">
                        <a class="btn btn-sm btn-default"
                           href="{{ route('admin.info.info',$chunk->id) }}">
                            全部
                        </a>
                        <a class="btn btn-sm btn-default {{ $append['is']=='is_new'?'active':'' }}"
                           href="{{ route('admin.info.info',$chunk->id) }}?is=is_new">
                            最新发布
                        </a>
                        <a class="btn btn-sm btn-default {{ $append['is']=='is_push'?'active':'' }}"
                           href="{{ route('admin.info.info',$chunk->id) }}?is=is_push">
                            推荐信息
                        </a>
                        <a class="btn btn-sm btn-default {{ $append['is']=='is_hot'?'active':'' }}"
                           href="{{ route('admin.info.info',$chunk->id) }}?is=is_hot">
                            热门信息
                        </a>
                    </div>
                </div>
                <div class="col-sm-3">
                    <form action="" method="get">
                        <div class="input-group">
                            <input type="text" class="input-sm form-control" placeholder="请输入信息名称/信息id" name="search"
                                   value="{{ $append['search'] }}">
                            <span class="input-group-btn">
                                <button class="btn btn-sm btn-default">搜索</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
            <div class="table-responsive">
                <table class="table table-striped b-t b-light">
                    <thead>
                    <tr>
                        <th style="width:20px;">
                            <label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                        <th class="col-md-4">标题</th>
                        <th class="col-md-2">分类</th>
                        <th class="col-md-2">排序</th>
                        <th class="col-md-2">编辑时间</th>
                        <th class="col-md-2">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @if( $infos->count() > 0 )
                        @foreach( $infos as $info )
                            <tr>
                                <td>
                                    <label class="checkbox m-n i-checks">
                                        <input type="checkbox" name="post[]" value="{{ $info->id }}"><i></i>
                                    </label>
                                </td>
                                <td>
                                    <a href="{{ route('admin.info.info',$chunk->id) }}?change=status&id={{ $info->id }}">
                                        @if( (bool)$info->status )
                                            <i class="fa-tags fa text-xs text-ff552e text-center-xs" title="信息开启"></i>
                                        @else
                                            <i class="fa-tags fa text-xs text-no text-center-xs" title="信息关闭"></i>
                                        @endif
                                    </a>
                                    <a href="{{ route('admin.info.info',$chunk->id) }}?change=is_new&id={{ $info->id }}"
                                       title="最新信息">
                                        @if( (bool)$info->is_new )
                                            <i class="ico icon-hourglass text-info text-xs text-center-xs"></i>
                                        @else
                                            <i class="ico icon-hourglass text-no text-xs text-center-xs"></i>
                                        @endif
                                    </a>
                                    <a href="{{ route('admin.info.info',$chunk->id) }}?change=is_push&id={{ $info->id }}"
                                       title="推荐信息">
                                        @if( (bool)$info->is_push )
                                            <i class="fa fa-thumbs-o-up text-success text-xs text-center-xs"></i>
                                        @else
                                            <i class="fa fa-thumbs-o-up text-no text-xs text-center-xs"></i>
                                        @endif
                                    </a>
                                    <a href="{{ route('admin.info.info',$chunk->id) }}?change=is_hot&id={{ $info->id }}"
                                       class="m-r"
                                       title="热门信息">
                                        @if( (bool)$info->is_hot )
                                            <i class="ico icon-fire text-danger text-xs text-center-xs"></i>
                                        @else
                                            <i class="ico icon-fire text-no text-xs text-center-xs"></i>
                                        @endif
                                    </a>
                                    <a target="_blank" href="{{ route('info',[$chunk['path'],$info->id]) }}">
                                        @if(!empty($info->image))
                                            <img src="{{ $info->image }}"
                                                 style="display: inline-block;height: 23px;margin-right: 5px">
                                        @endif
                                        {{ $info->name }}
                                    </a>
                                </td>
                                <td title="{{ $info->sort_name }}">{{ subtext($info->sort_name,10) }}</td>
                                <td data-id="{{ $info->id }}" data-xindex="{{ $info->xindex }}">
                                    {{--<input class="slider slider-horizontal form-control" type="text"--}}
                                    {{--value="{{ $info->xindex }}"--}}
                                    {{--data-slider-min="1" data-slider-max="100" data-slider-step="1"--}}
                                    {{--data-slider-value="{{ $info->xindex }}"--}}
                                    {{--data-slider-orientation="horizontal" name="xindex">--}}
                                    <input class="form-control setxindex"
                                           type="number"
                                           name="xindex"
                                           data-id="{{ $info->id }}"
                                           value="{{ $info->xindex }}">
                                </td>
                                <td>{{ $info->updated_at }}</td>
                                <td>
                                    <a target="_blank" href="{{ route('admin.info.info_edit',[$chunk->id,$info->id]) }}"
                                       class="btn btn-xs btn-default">编辑</a>
                                    <a href="{{ route('admin.info.info',$chunk->id) }}?del={{ $info->id }}"
                                       class="btn btn-xs btn-danger">删除</a>
                                </td>
                            </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="6" align="center">
                                暂无 {{ $chunk->name }} 模块的信息,请
                                <a class="text-danger" href="{{ route('admin.info.info_add',$chunk->id) }}">
                                    添加
                                </a>
                                !
                            </td>
                        </tr>
                    @endif
                    </tbody>
                </table>
            </div>
            <footer class="panel-footer">
                <div class="row">
                    <div class="col-sm-5 hidden-xs">
                        <form action="" method="post">
                            {!! csrf_field() !!}
                            <input type="hidden" name="info_id" value="">
                            <select class="input-sm form-control input-s-sm inline v-middle" name="sort">
                                @if( !empty($sorts) )
                                    @foreach( $sorts as $sortlv1 )
                                        <option value="{{ $sortlv1['id'] }}">{{ $sortlv1['name'] }}</option>
                                        @if( !empty($sortlv1['children']) )
                                            @foreach( $sortlv1['children'] as $sortlv2 )
                                                <option value="{{ $sortlv2['id'] }}">--{{ $sortlv2['name'] }}</option>
                                                @if( !empty($sortlv2['children']) )
                                                    @foreach( $sortlv2['children'] as $sortlv3 )
                                                        <option value="{{ $sortlv3['id'] }}">
                                                            ----{{ $sortlv3['name'] }}</option>
                                                        @if( !empty($sortlv3['children']) )
                                                            @foreach( $sortlv3['children'] as $sortlv4 )
                                                                <option value="{{ $sortlv4['id'] }}">
                                                                    ----{{ $sortlv4['name'] }}</option>
                                                                @if( !empty($sortlv4['children']) )
                                                                    @foreach( $sortlv4['children'] as $sortlv5 )
                                                                        <option value="{{ $sortlv5['id'] }}">
                                                                            ----{{ $sortlv5['name'] }}</option>
                                                                    @endforeach
                                                                @endif
                                                            @endforeach
                                                        @endif
                                                    @endforeach
                                                @endif
                                            @endforeach
                                        @endif
                                    @endforeach
                                @endif
                            </select>
                            <button class="btn btn-sm btn-default" name="active" value="changesort">将选中信息移动至此分类</button>
                            <button class="btn btn-sm btn-default" name="active" value="delinfo">将选中信息删除</button>
                        </form>
                    </div>
                    <div class="col-sm-3 text-center">
                        <small class="text-muted inline m-t-sm m-b-sm">显示 {{ $infos->count() }} 条
                            共 {{ $infos->total() }} 条
                        </small>
                    </div>
                    <div class="col-sm-4 text-right text-center-xs">
                        @if(!empty($append))
                            {!! $infos->appends($append)->links() !!}
                        @else
                            {!! $infos->links() !!}
                        @endif
                    </div>
                </div>
            </footer>
        </section>
    </div>
@endsection

@section('css')
    <link rel="stylesheet" href="/public/theme/js/slider/slider.css" type="text/css"/>
    <style>
        .slider {
            margin-top: 0px;
        }
    </style>
@endsection

@section('js')
    <!-- slider -->
    <script src="/public/theme/js/slider/bootstrap-slider.js"></script>

    <script>
        $('button[name="active"]').click(function () {
            var info = [];
            $('input[name="post[]"]:checked').each(function () {
                info.push($(this).val());
            })
            $('input[name="info_id"]').val(info);
        })
    </script>

    <script>
        //记录xindex函数
        function setXindex(th) {
            //得到当前的数值
            var xindex = th.find('.tooltip-inner').html();
            //得到当前的id
            var infoId = th.parent().attr('data-id');
            //得到原始的xindex
            var srcxindex = th.parent().attr('data-xindex');
            if (xindex != srcxindex) {
                $.post('{{ route('admin.info.xindex') }}', {id: infoId, xindex: xindex}, function () {
                    th.parent().attr('data-xindex', xindex);
                });
            }
        }

        var key = 0;

        $(function () {
            $('.slider').hover(function () {
                //定时发送
                var th = $(this);
                key = setInterval(function () {
                    setXindex(th);
                }, 500);
            }, function () {
                //关闭定时
                clearInterval(key);
                //及时发送
                setXindex($(this));
            })
        })

        $('.setxindex').change(function () {
            //得到当前的数值
            var xindex = $(this).val();
            //得到当前的id
            var infoId = $(this).attr('data-id');

            $.post('{{ route('admin.info.xindex') }}', {id: infoId, xindex: xindex});
        })
    </script>

@endsection